# encoding: utf-8
# 医生模块
import mod_db


def get_detail(info_id):
    query = {'_id': info_id}
    doc = mod_db.find_one('hospital', 'doctor', query)
    if doc is None:
        return None
    else:
        return doc


def get_detail_list(info_ids):
    query = {'_id': {'$in': info_ids}}
    cursor = mod_db.find_list('hospital', 'doctor', query)
    res_list = []
    for unit in cursor:
        unit["url"] = "doctor?id=" + str(unit["_id"])
        res_list.append(unit)
    return res_list


def get_list():
    query = {}
    col = mod_db.get_col('hospital', 'doctor')
    cursor = col.find(query).sort('index')
    res_list = []
    for unit in cursor:
        if unit["logo"] == "http://maislook.oss-cn-shanghai.aliyuncs.com/hos_doctor_logo.jpg":
            continue
        else:
            unit["url"] = "doctor?id=" + str(unit["_id"])
            res_list.append(unit)
    return res_list


def get_list_by_department_name(department):
    query = {'department': department}
    cursor = mod_db.find_list('hospital', 'doctor', query)
    res_list = []
    for unit in cursor:
        if unit["logo"] == "http://maislook.oss-cn-shanghai.aliyuncs.com/hos_doctor_logo.jpg":
            continue
        else:
            unit["url"] = "doctor?id=" + str(unit["_id"])
            res_list.append(unit)
    return res_list


def get_list_by_title(title):
    query = {'title': title}
    cursor = mod_db.find_list('hospital', 'doctor', query)
    res_list = []
    for unit in cursor:
        if unit["logo"] == "http://maislook.oss-cn-shanghai.aliyuncs.com/hos_doctor_logo.jpg":
            continue
        else:
            unit["url"] = "doctor?id=" + str(unit["_id"])
            res_list.append(unit)
    return res_list


def get_list_by_page(current_page):
    cursor = mod_db.get_by_page('hospital', 'doctor', {}, current_page)
    res_list = []
    for unit in cursor:
        if unit["logo"] == "http://maislook.oss-cn-shanghai.aliyuncs.com/hos_doctor_logo.jpg":
            continue
        else:
            unit["url"] = "doctor?id=" + str(unit["_id"])
            res_list.append(unit)
    return res_list
